import sys, os, random
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
import PySide6
from PySide6 import QtCore, QtWidgets, QtGui
from PySide6.QtCore import QModelIndex
from PySide6.QtGui import QStandardItemModel
from PySide6.QtWidgets import QTableWidgetItem, QTableWidget, QHeaderView, \
    QTableView, QItemDelegate


class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.dataTableView = QTableView(self)
        self.init_widget()
        self.dataTableView.show()

    def init_widget(self):
        tableModel = QStandardItemModel(4, 6)
        self.dataTableView.setModel(tableModel)
        delegate = QItemDelegate()
        self.dataTableView.setItemDelegate(delegate)
        for row in range(4):
            for col in range(6):
                index = tableModel.index(row, col, QModelIndex())
                tableModel.setData(index, (row + 1) * (col + 1))
        self.dataTableView.setWindowTitle("电子表格")


# 初始化QT 插件环境
def init_env():
    dirname = os.path.dirname(PySide6.__file__)
    plugin_path = os.path.join(dirname, 'plugins', 'platforms')
    print(plugin_path)
    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path


if __name__ == "_main__":
    init_env()
    app = QtWidgets.QApplication([])
    widget = MyWidget()
    widget.resize(1200, 600)
    widget.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    action = []
    for i in range(1000):
        action.append({
            "_index": "s2",
            "_type": "doc",
            "_source": {
                "title": i
            }
        })
    es = Elasticsearch('http://192.168.2.186:9200')
    bulk(es, action)
